<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" :append-to-body="true" width="65%" @open="handleOpen" @close="handleClose" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-tabs type="border-card">
      <el-tab-pane label="基本信息">
        <div class="tab-wrap">
        <el-form ref="mainFrom" :model="mainFrom" label-width="100px" :rules="mainRules"  size="small">
          <el-row :gutter="20">
            <el-form-item label="病人主诉:" prop="description">
              <el-input type="textarea" rows="4" v-model="mainFrom.description"  placeholder="病人主诉"></el-input>
            </el-form-item>
            <div style="text-align: right">
              <el-button size="mini" :disabled="mainFrom.description==''" @click="getRecord">
                查询
              </el-button>
            </div>
            <el-form-item v-if="inquiryList2.length" label="经过药物治疗后，现在的症状变化是:" label-width="300px" >
              <el-radio-group v-model="nowchange" >
                <el-radio :label="item.value" :key="item.value" v-for="item in nowChanges">{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-row>
          <el-row :gutter="20">
<!--            <el-col :span="6">-->
<!--              <el-form-item label="图片:">-->
<!--                <el-upload-->
<!--                  class="avatar-uploader"-->
<!--                  action="#"-->
<!--                  accept=".jpg,.jpeg,.png,.gif"-->
<!--                  :before-upload="beforeUpload"-->
<!--                  :http-request="uploadUrl"-->
<!--                  :show-file-list="false"-->
<!--                >-->
<!--                  <el-button type="primary"  size="small">{{mainFrom.url?'重新上传':'上传'}}</el-button>-->
<!--                </el-upload>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :span="10" v-if="mainFrom.descriptionFile">
              <div class="demo-image__preview">
                <el-image
                  style="width: 100px; height: 100px"
                  :src="mainFrom.descriptionFile"
                  :preview-src-list="srcList">
                </el-image>
              </div>
            </el-col>
          </el-row>
<!--          <el-row :gutter="20">-->
<!--            <el-form-item label="问诊单:" prop="classification">-->
<!--              <el-select v-model="mainFrom.classification"  placeholder="问诊单" class="w-240" multiple @change="handleClassification">-->
<!--                <el-option-->
<!--                  v-for="item in inquiryOptions"-->
<!--                  :key="item.id"-->
<!--                  :label="item.inquiryName"-->
<!--                  :value="item.id"-->
<!--                />-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-row>-->
          <!-- 问诊列表 -->
          <el-row :gutter="20" v-if="inquiryList2.length">
            <template >
                <div class="symptom-wrap">
                  <div class="title">症状与查体</div>
                  <el-table
                  size="small"
                  :data="inquiryList2"
                  border
                  style="width: 100%">
                    <el-table-column type="index" label="序号" width="100"/>
                    <el-table-column
                      prop="content"
                      label="诊断结果">
                      <template slot-scope="scope">
                        {{resultFilter(scope.row )}}
                      </template>
                    </el-table-column>
                  </el-table>
                  <!-- <el-button @click="inq2Click" size="mini" class="m-t-20">辅助诊断</el-button> -->

                  <div class="m-t-20" v-for="(item, index) in inquiryList3" :key="index">
                    <div class="symptom-wrap">
                      <!--                  <div class="title">{{ getInqueryName(item.id) }}</div>-->
                      <el-table
                        size="small"
                        :data="item.list"

                        border
                        style="width: 100%">
                        <el-table-column
                          prop="symptomName"
                          label="症状">
                        </el-table-column>
                        <el-table-column
                          label="是否有此症狀">
                          <template slot-scope="scope">

                            <el-select :collapse-tag="true"
                                       @change="(val)=>kssChange(item.id,val,scope.$index)" v-if="scope.row.id == '1771400266695450625'" v-model="kss" multiple placeholder="请选择">
                              <el-option
                                v-for="item in kssList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                              </el-option>
                            </el-select>
                            <el-select v-else-if="scope.row.id == '1771400266733199362'" :collapse-tag="true"
                                       @change="(val)=>elseChange(item.id,val,scope.$index)" v-model="gm" multiple placeholder="请选择">
                              <el-option
                                v-for="item in gmList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                              </el-option>
                            </el-select>
                            <el-select v-else-if="scope.row.id == '1771400266766753794'" :collapse-tag="true"
                                       @change="(val)=>elseChange(item.id,val,scope.$index)" v-model="gm2" multiple placeholder="请选择">
                              <el-option
                                v-for="item in gmList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                              </el-option>
                            </el-select>
                            <el-select v-else-if="scope.row.id == '1771400266913554433'" :collapse-tag="true"
                                       @change="(val)=>elseChange(item.id,val,scope.$index)" v-model="treat" multiple placeholder="请选择">
                              <el-option
                                v-for="item in treatList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id">
                              </el-option>
                            </el-select>
                            <!--支气管舒张阳性-->
                            <div class="flex-center"  v-else-if="scope.row.id == '1771400267349762050'">
                              <el-radio-group v-model="scope.row.check">
                                <el-radio :label="true">是</el-radio>
                                <el-radio :label="false">否</el-radio>
                              </el-radio-group>
                              <el-upload
                                class="avatar-uploader ml-20"
                                action="#"
                                accept=".jpg,.jpeg,.png,.gif"
                                :before-upload="beforeUpload"
                                :http-request="(file)=>{uploadUrl2(file,item.id,scope.$index)}"
                                :show-file-list="false"
                              >
                                <el-button :loading="loading" type="primary"  size="small">{{imageUrl?'重新上传':'上传'}}</el-button>
                              </el-upload>
                              <span class="ml-20">{{uploadText}}</span>
                            </div>

                            <el-radio-group v-model="scope.row.check" v-else >
                              <el-radio :label="true">是</el-radio>
                              <el-radio :label="false">否</el-radio>
                            </el-radio-group>
                            <!--                      <el-checkbox v-model="scope.row.check" @change="handleChange(item.id, scope.row.check, scope.$index)"></el-checkbox>-->
                          </template>
                        </el-table-column>
                      </el-table>
                    </div>
                  </div>
                </div>
            </template>
          </el-row>
          <el-row :gutter="20" v-else>
            <template >
              <div v-for="(item, index) in inquiryList" :key="index">
                <div class="symptom-wrap">
<!--                  <div class="title">{{ getInqueryName(item.id) }}</div>-->
                  <el-table
                  size="small"
                  :data="item.list"
                  border
                  style="width: 100%">
                  <el-table-column
                    prop="symptomName"
                    label="症状">
                  </el-table-column>
                  <el-table-column
                    label="是否有此症狀">
                    <template slot-scope="scope">

                      <el-select :collapse-tag="true"
                                 @change="(val)=>kssChange(item.id,val,scope.$index)" v-if="scope.row.id == '1771400266695450625'" v-model="kss" multiple placeholder="请选择">
                        <el-option
                          v-for="item in kssList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                      <el-select v-else-if="scope.row.id == '1771400266733199362'" :collapse-tag="true"
                                 @change="(val)=>elseChange(item.id,val,scope.$index)" v-model="gm" multiple placeholder="请选择">
                        <el-option
                          v-for="item in gmList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                      <el-select v-else-if="scope.row.id == '1771400266766753794'" :collapse-tag="true"
                                 @change="(val)=>elseChange(item.id,val,scope.$index)" v-model="gm2" multiple placeholder="请选择">
                        <el-option
                          v-for="item in gmList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                      <el-select v-else-if="scope.row.id == '1771400266913554433'" :collapse-tag="true"
                                 @change="(val)=>elseChange(item.id,val,scope.$index)" v-model="treat" multiple placeholder="请选择">
                        <el-option
                          v-for="item in treatList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id">
                        </el-option>
                      </el-select>
                      <!--支气管舒张阳性-->
                      <div class="flex-center"  v-else-if="scope.row.id == '1771400267349762050'">
                        <el-radio-group v-model="scope.row.check">
                          <el-radio :label="true">是</el-radio>
                          <el-radio :label="false">否</el-radio>
                        </el-radio-group>
                        <el-upload
                          class="avatar-uploader ml-20"
                          action="#"
                          accept=".jpg,.jpeg,.png,.gif"
                          :before-upload="beforeUpload"
                          :http-request="(file)=>{uploadUrl2(file,item.id,scope.$index)}"
                          :show-file-list="false"
                        >
                          <el-button :loading="loading" type="primary"  size="small">{{imageUrl?'重新上传':'上传'}}</el-button>
                        </el-upload>
                        <span class="ml-20">{{uploadText}}</span>
                      </div>
                      <div class="flex-center"  v-else-if="scope.row.id == '1814851514517909515'">
                        <el-radio-group v-model="scope.row.check">
                          <el-radio :label="true">是</el-radio>
                          <el-radio :label="false">否</el-radio>
                        </el-radio-group>
                        <el-button size="mini" type="primary"  class="ml-20" v-if="scope.row.check" @click="envModal">环境规避措施</el-button>
                      </div>
                      <el-radio-group v-model="scope.row.check" v-else >
                        <el-radio :label="true">是</el-radio>
                        <el-radio :label="false">否</el-radio>
                      </el-radio-group>
<!--                      <el-checkbox v-model="scope.row.check" @change="handleChange(item.id, scope.row.check, scope.$index)"></el-checkbox>-->
                    </template>
                  </el-table-column>
                  </el-table>
                </div>
              </div>
            </template>
          </el-row>
          <el-row :gutter="20">
<!--            <el-button type="primary" size="mini" @click="resultAdd">添加诊断结果</el-button>-->
            <el-button type="success" size="mini" v-if="!inquiryList2.length" @click="handleDiagnosis">诊断</el-button>
          </el-row>
          <el-row :gutter="20" v-if="diagnosisTable.length > 0">
            <el-table
                size="small"
                :data="diagnosisTable"
                border
                style="width: 100%">
                <el-table-column type="index" label="序号" width="100"/>
                <el-table-column
                  prop="content"
                  label="诊断结果">
                </el-table-column>
                <el-table-column
                  width="90"
                  label="操作">
                  <template slot-scope="scope">
                    <span @click="handleDelete(scope.$index)" class="oper">
                      <i class="el-icon-delete"></i>
                    </span>
                  </template>
                </el-table-column>
              </el-table>
          </el-row>
          <el-row :gutter="20" v-if="!inquiryList2.length">
            <el-form-item label="诊断结果:" prop="result" >
              <el-input v-model="mainFrom.result"></el-input>
<!--              <div v-if="showText">似为支气管哮喘，建议辅助检查</div>-->
<!--              <el-checkbox-group v-else v-model="mainFrom.result">-->
<!--                <el-checkbox :label="item.value" :key="item.value" v-for="item in ruleTypeList">{{item.label}}</el-checkbox>-->
<!--                <el-button style="margin-left: 20px" type="warning" @click="getMedication">用药</el-button>-->
<!--              </el-checkbox-group>-->

<!--              <el-input type="textarea" rows="4" v-model="mainFrom.result"  placeholder="诊断结果"></el-input>-->
            </el-form-item>
            <!-- <el-form-item label="化验单:" prop="pictureUrl" ref=addPictureLists >
              <upload-area @update="(val)=>{pictureUrl = val;$refs.addPictureLists.clearValidate()}"
                ref="upload-addPictureLists" :limit="10"></upload-area>
            </el-form-item> -->
          </el-row>

          <el-row :gutter="20" v-if="inquiryList2.length">
            <el-button type="text" @click="questionClick">{{questionObj.name}}</el-button>
            <div class="flex-colunm">
              <span v-if="questionScore!==''">得分：{{questionScore}}</span>
              <span>{{questionResult}}</span>
            </div>
          </el-row>

          <el-row :gutter="20" v-if="inquiryList2.length && !goodControl">
            <div class="title">哮喘分期</div>
            <el-form ref="wjFrom" label-position="top"  :model="wjFrom" :rules="wjRules">
              <el-form-item   label="喘息或咳嗽或胸闷或气促" prop="pant">
                <el-select v-model="wjFrom.pant">
                  <el-option v-for="(option,i) in pantList" :key="i" :label="option.name"
                             :value="option.value" />
                </el-select>
              </el-form-item>
              <el-form-item   label="双肺可闻及散在或弥漫性哮鸣音(喘鸣音),呼气相为主或呼气相延长" prop="mainly">
                <el-select v-model="wjFrom.mainly">
                  <el-option v-for="(option,i) in mainList" :key="i" :label="option.name"
                             :value="option.value" />
                </el-select>
              </el-form-item>
              <el-form-item   label="肺通气功能检测正常且维持三个月" prop="maintain">
                <el-radio-group v-model="wjFrom.maintain">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-form-item   label="既往确诊过哮喘(怀疑过哮喘,反复喘息史)" prop="previously">
                <el-radio-group v-model="wjFrom.previously">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </el-form-item>
              <el-button @click="fenqiClick">分期</el-button><br>
              <el-select class="m-t-20" v-model="fenqi"  v-show="fenqi!==''">
                <el-option v-for="(option,i) in fqList" :key="i" :label="option.name"
                           :value="option.value" />
              </el-select>
              <div class="title m-t-20" v-show="fenqi!==''">哮喘分级</div>

            </el-form>

          </el-row>
          <el-row :gutter="20" v-if="fenqi === 1">
            <el-form ref="ageForm1" label-position="top" v-if="age >= 6"  :model="ageForm1" :rules="ageRules1">
              <el-form-item  :label="item.label" :key="item.key" :prop="item.key" v-for="item in featureList1">
                <el-select v-model="ageForm1[item.key]">
                  <el-option v-for="option in item.options" :key="'ageForm1'+option.value" :label="option.name"
                             :value="option.value" />
                </el-select>
              </el-form-item>
            </el-form>
            <el-form ref="ageForm2" label-position="top"  v-else  :model="ageForm2" :rules="ageRules2">
              <el-form-item  :label="item.label" :key="item.key" :prop="item.key" v-for="item in featureList2">
                <el-select v-model="ageForm2[item.key]">
                  <el-option v-for="option in item.options" :key="'ageForm2'+option.value" :label="option.name"
                             :value="option.value" />
                </el-select>
              </el-form-item>
            </el-form>
            <el-button @click="fenjiClick" type="primary">分级</el-button>
            <div class="title m-t-20" v-show="result1!==''">哮喘急性发作严重度分级</div>
            <el-select class="m-t-20" v-show="result1!==''&& age>=6" v-model="result1">
              <el-option v-for="option in result1Options" :key="option.value" :label="option.name"
                         :value="option.value" />
            </el-select>
            <el-select class="m-t-20" v-show="result1!==''&& age<6" v-model="result1">
              <el-option v-for="option in result1OptionsLess6" :key="option.value" :label="option.name"
                         :value="option.value" />
            </el-select>
          </el-row>
          <!--慢性分期-->
          <el-row :gutter="20" v-if="fenqi === 2">
            <el-form ref="ageForm3" label-position="top" v-if="age >= 6"  :model="ageForm3" :rules="ageRules3">
              <el-form-item  :label="item.label" :key="item.key" :prop="item.key" v-for="item in featureList3">
                <el-select v-model="ageForm3[item.key]" placeholder="请选择">
                  <el-option
                    v-for="item in item.list"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
                  </el-option>
                </el-select>
                <!--                <el-radio v-model="ageForm3[item.key]" :label="2">是</el-radio>-->
                <!--                <el-radio v-model="ageForm3[item.key]" :label="1">否</el-radio>-->
              </el-form-item>
            </el-form>
            <el-form ref="ageForm4" label-position="top" v-else  :model="ageForm4" :rules="ageRules4">
              <el-form-item  :label="item.label" :key="item.key" :prop="item.key" v-for="item in featureList4">
                <el-select v-model="ageForm4[item.key]" placeholder="请选择">
                  <el-option
                    v-for="item in item.list"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value">
                  </el-option>
                </el-select>
                <!--                <el-radio v-model="ageForm4[item.key]" :label="2">是</el-radio>-->
                <!--                <el-radio v-model="ageForm4[item.key]" :label="1">否</el-radio>-->
              </el-form-item>
            </el-form>
            <el-button @click="manxingFenjiClick" type="primary">分级</el-button>
            <div class="title m-t-20" v-show="controlLevel!==''">哮喘控制水平的分级</div>
            <el-select class="m-t-20" v-show="controlLevel!==''" v-model="controlLevel">
              <el-option v-for="option in result2Options" :key="option.value" :label="option.name"
                         :value="option.value" />
            </el-select>
            <div class="title m-t-20" v-show="degree!==''">病情严重程度分级</div>
            <el-select class="m-t-20" v-show="degree!==''" v-model="degree">
              <el-option v-for="option in result3Options" :key="option.value" :label="option.name"
                         :value="option.value" />
            </el-select>
          </el-row>
          <el-form-item label="缓解药物:">
            <el-select v-model="mainFrom.medicate" collapse-tags	 multiple  @change="val=>{medicateChange(val,'medicineOptions')}"  placeholder="请选择" class="w-240">
              <el-option
                v-for="item in medicineOptions"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="控制药物:">
            <el-select v-model="mainFrom.medicate3" collapse-tags	 multiple  @change="val=>{medicateChange(val,'medicineOptions3')}"  placeholder="请选择" class="w-240">
              <el-option
                v-for="item in medicineOptions3"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="生物制剂:">
            <el-select v-model="mainFrom.medicate4" collapse-tags	 multiple @change="val=>{medicateChange(val,'medicineOptions4')}" placeholder="请选择" class="w-240">
              <el-option
                v-for="item in medicineOptions4"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="脱敏治疗:">
            <el-select v-model="mainFrom.medicate5" collapse-tags	 multiple  @change="val=>{medicateChange(val,'medicineOptions5')}"  placeholder="请选择" class="w-240">
              <el-option
                v-for="item in medicineOptions5"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <div v-for="item in medicineDisplayList" class="flex-center" style="margin-top: 10px">
            <span>{{item.name}}</span>
            <el-select v-model="item.dosageValue"  placeholder="请选择" class="w-240 ml-20">
              <el-option
              v-for="(dosage,i) in item.dosage"
              :key="i"
              :label="dosage"
              :value="dosage"
              />
            </el-select>
            <div class="flex-center ml-10" :key="i" v-for="(spe,i) in item.specifications">
              <el-input v-model="item[`spe${i}`]" style="width: 50px"></el-input>
              <span class="ml-10">{{spe}}</span>
            </div>
            <el-input class="ml-10" v-model="item.datevalue" style="width: 50px" ></el-input>
            <span  class="ml-10">{{item.course}}</span>
            <div class="flex-center ml-10" v-if="['沙丁胺醇气雾剂','丙酸氟替卡松气雾剂','沙美特罗替卡松气雾剂','布地奈德气雾剂'].includes(item.name)">
              <el-button type="primary" size="mini" @click="methodsClick(1)">使用方法</el-button>
              <el-button size="mini" class="ml-10" @click="quatityClick(1)">质量控制</el-button>
            </div>
            <div class="flex-center ml-10" v-if="['沙美特罗替卡松粉吸入剂'].includes(item.name)">
              <el-button type="primary" size="mini" @click="methodsClick(2)">使用方法</el-button>
              <el-button size="mini" class="ml-10" @click="quatityClick(2)">质量控制</el-button>
            </div>
            <div class="flex-center ml-10" v-if="['布地奈德福莫特罗吸入粉雾剂'].includes(item.name)">
              <el-button type="primary" size="mini" @click="methodsClick(3)">使用方法</el-button>
              <el-button size="mini" class="ml-10" @click="quatityClick(3)">质量控制</el-button>
            </div>
          </div>
<!--          <el-row :gutter="20">-->
<!--            <el-form-item label="用药:" prop="medicate">-->
<!--              <el-input type="textarea" rows="4" v-model="mainFrom.medicate"  placeholder="用药"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-row>-->
<!--          <el-row :gutter="20">-->
<!--            <el-form-item label="医嘱:" prop="charge">-->
<!--              <el-input type="textarea" rows="4" v-model="mainFrom.charge"  placeholder="医嘱"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-row>-->
        </el-form>


        <div class="sub-bottom">
          <el-button type="primary" size="mini" @click="mainFromSubmit">提交</el-button>
        </div>
       </div>
      </el-tab-pane>
      <el-tab-pane label="报告单">
        <div class="tab-wrap">
          <el-form ref="twoFrom" :rules="twoFromRules" :model="twoFrom" label-width="120px" size="small">

            <el-row :gutter="20">

              <el-form-item label="报告单:">
                <el-select v-model="twoFrom.caseReportCode"  placeholder="报告单" class="w-240">
                <el-option
                  v-for="item in caseReportOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
              </el-form-item>
            </el-row>
            <el-row :gutter="20" v-if="twoFrom.caseReportCode">
              <el-col :span="24">
                <el-form-item label="上传报告单:" v-if="twoFrom.caseReportCode !== 'OTHER'">
                  <el-upload
                    class="avatar-uploader"
                    action="#"
                    accept=".jpg,.jpeg,.png,.gif"
                    :http-request="uploadReport"
                    :show-file-list="false"
                  >
                    <el-button type="primary"  size="small">上传报告单</el-button>
                  </el-upload>
                </el-form-item>
                <el-form-item label="上传多张图片:" v-else ref="reportPictures">
                  <upload-area @update="(val)=>{reportPictures = val;$refs.reportPictures.clearValidate()}"
                    ref="upload-reportPictures" :limit="10"></upload-area>
                </el-form-item>

              </el-col>
            </el-row>
            <div class="report-wrap">
              <el-tabs :tab-position="tabPosition" @tab-click="handleTabClick">
                <el-tab-pane :label="tab.reportName" v-for="(tab, index) in reportList" :key="index" >
                  <div class="report-content">
                    <div v-for="(item, index) in tab.reportData" :key="'col' + index" class="col">
                      <div v-for="(k, currentIndex) in item" :key="'cell' + currentIndex" class="cell">
                        <template v-if="currenRowIndex === currentIndex">
                          <template v-if="k.key !== 'save'">
                            <el-input type="text" v-model="k.value" size="mini"></el-input>
                          </template>
                          <template v-else>
                            <span :class="k.key === 'save' ? blue:''" @click="handleSave(tab.uuid, item, index, k, currentIndex)">{{ k.value }}</span>
                          </template>
                        </template>
                        <template v-else>
                          <span :class="k.key === 'edit' ? blue:''" @click="handleEdit(tab.uuid, item, index, k, currentIndex)">{{ k.value }}</span>
                        </template>
                        </div>
                    </div>
                  </div>
                </el-tab-pane>
              </el-tabs>
            </div>
          </el-form>
          <div class="sub-bottom">
            <el-button type="primary" size="mini" @click="twoFromSubmit">提交</el-button>
          </div>
        </div>
      </el-tab-pane>
    </el-tabs>
    <question-naire ref="question" @submit="questionSubmit"></question-naire>
    <env-modal ref="env"></env-modal>
    <quatity-modal ref="quatity"></quatity-modal>
    <methodsModal ref="methods"></methodsModal>
    <quatity-modal-2 ref="quatity2"></quatity-modal-2>
    <methods-modal-2 ref="methods2"></methods-modal-2>
    <quatity-modal-3 ref="quatity3"></quatity-modal-3>
    <methods-modal-3 ref="methods3"></methods-modal-3>


  </el-dialog>

</template>
<script>
import { uploadFile, manxingApi,over6Api,above6Api,saveOtherReport,getRecordApi2,uploadFile2,uploadFile3,saveMedicine,getAgeApi,inquiryTableList, fenjiApi,getFuzhuCheckApi,getDetail, peportInfoOne, getMedication,peportInfoThree,getRuleType, getDiagnosticId, algorithmType, filetwo, editReportData, diagnosis,getRecordApi,saveWjApi,medicineList2
  ,medicineList3,medicineList4,medicineList5
} from "@/api/infoManagement/inqueryRecord";
import questionNaire from './questionNaire'
import func from "@/util/func";
import {deepFind} from "../../../util/util";
  import uploadArea from '@/components/upload/index'
  import envModal from './envModal.vue'
  import quatityModal from "./quatityModal.vue";
  import methodsModal from "./methodsModal.vue";
  import methodsModal2 from "./methodsModal2.vue";
  import methodsModal3 from "./methodsModal3.vue";
  import quatityModal3 from "./quatityModal3.vue";
  import quatityModal2 from "./quatityModal2.vue";
export default {
  data() {
    return {
      reportPictures:[],
      id: '',
      questionResult: '',
      questionScore: '',
      imageUrl: '',
      uploadText: '',
      dialogFormVisible: false,
      loading: false,
      goodControl: true,//是否控制良好
      srcList: [],
      treat:[],
      medicineOptions:[],
      medicineOptions3:[],
      medicineOptions4:[],
      medicineOptions5:[],
      treatList:[
        {
          id:1,
          name:'布地奈德'
        },  {
          id:2,
          name:'特布他林'
        },  {
          id:3,
          name:'沙丁胺醇'
        },  {
          id:4,
          name:'异丙托溴铵'
        },  {
          id:5,
          name:'丙酸氟替卡松(辅舒酮)'
        },  {
          id:6,
          name:'布地奈德福莫特罗(信必可)'
        },  {
          id:7,
          name:'沙美特罗替卡松(舒利迭)'
        },  {
          id:8,
          name:'沙丁胺醇气雾剂(万托林)'
        },{
          id:9,
          name:'孟鲁司特'
        },{
          id:10,
          name:'西替利嗪'
        },{
          id:11,
          name:'地氯雷他定'
        },{
          id:0,
          name:'无'
        },
      ],
      gm2:[],

      gm:[],
      gmList:[
        {
          id:1,
          name:'食物过敏'
        },{
          id:2,
          name:'牛奶蛋白过敏'
        },{
          id:3,
          name:'特应性皮炎'
        },{
          id:4,
          name:'过敏性鼻炎'
        },{
          id:5,
          name:'过敏性结膜炎'
        },{
          id:6,
          name:'荨麻疹'
        },{
          id:0,
          name:'无'
        },
      ],
      kss: [],//抗生素
      kssList: [
        {
          id:1,
          name:'阿莫西林'
        }, {
          id:2,
          name:'头孢类'
        },{
          id:3,
          name:'阿奇霉素'
        },{
          id:4,
          name:'红霉素'
        },{
          id:5,
          name:'庆大霉素'
        },{
          id:6,
          name:'链霉素'
        },{
          id:7,
          name:'阿米卡星'
        },{
          id:8,
          name:'妥布霉素'
        },{
          id:9,
          name:'诺氟沙星'
        },{
          id:10,
          name:'左氧氟沙星'
        },{
          id:11,
          name:'环丙沙星'
        },{
          id:12,
          name:'莫西沙星'
        },{
          id:13,
          name:'吉米沙星'
        },{
          id:0,
          name:'无'
        },
      ],//抗生素
      showText:false,
      wjFrom:{
        previously:1,
        maintain:1,
        mainly:'',
        pant:'',

      },
      wjRules:{
        previously: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        maintain: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        mainly: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        pant: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
      },

      mainFrom: {
        result:[],
        description: '',
        descriptionFile: '',
        // classification: [],
        medicate: '',
        charge: ''
      },
      mainRules: {
        description: [
          { required: true, message: '请输入病人主诉', trigger: 'blur' }
        ],
        // classification: [
        //   { required: true, message: '请选择问诊单', trigger: 'change' }
        // ],
        // medicate: [
        //   { required: true, message: '请输入用药', trigger: 'blur' }
        // ],
        result:[
          { required: true, message: '请选择诊断结果', trigger: 'blur' }
        ],
        // charge: [
        // { required: true, message: '请输入医嘱', trigger: 'blur' }
        // ]
      },
      ruleTypeList: [],
      inquiryOptions: [],
      inquiryList: [],
      inquiryList2: [],//不为空是复查
      inquiryList3: [],
      diagnosisTable: [],
      // 表单二
      caseReportOptions: [],
      currenRowIndex: -1,
      reportList: [],
      twoFrom: {
        caseReportCode: ''
      },
      nowchange:'',
      nowChanges:[
        {
          label:'无变化',
          value:1,
        },{
          label:'减轻',
          value:2
        },{
          label:'完全缓解',
          value:3
        },{
          label:'加重',
          value:4
        },
      ],
      pantList:[
        {
          name:'突然出现或加重',
          value:1
        }, {
          name:'近3个月内不同频度地出现',
          value:2
        },{
          name:'症状消失时间>3个月',
          value:3
        },
      ],
      mainList:[
        {
          name:'存在',
          value:1
        },{
          name:'消失时间>3个月',
          value:2
        }
      ],
      fqList:[
        {
          name:'急性发作期',
          value:1
        },{
          name:'慢性持续期',
          value:2
        },{
          name:'临床缓解期',
          value:3
        },{
          name:'以上都不是',
          value:4
        },
      ],
      age:'',
      fenqi:'',
      ageForm1:{
        breath:'',
        position:'',
        speech:'',
        consciousness:'',
        breathing:'',
        sound:'',
        pulse:'',
        pef:'',
        oxygen:'',
      },
      ageRules1:{
        breath: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        position: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        speech: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        consciousness: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        breathing: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        sound: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        pulse: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        pef: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        oxygen: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
      },
      featureList1:[
        {
          key:'breath',//气短
          label:'气短',
          options:[
            {
              name:'走路时',
              value:1
            },{
              name:'说话时',
              value:2
            },{
              name:'休息时',
              value:3
            },{
              name:'呼吸不整',
              value:4
            },
          ]
        },{
          key:'position',
          label:'体位',
          options:[
            {
              name:'可平卧',
              value:1
            },{
              name:'喜坐位',
              value:2
            },{
              name:'前弓位',
              value:3
            },{
              name:'不定',
              value:4
            },
          ]
        },{
          key:'speech',//讲话方式
          label:'讲话方式',
          options:[
            {
              name:'能成句',
              value:1
            },{
              name:'成短句',
              value:2
            },{
              name:'说单字',
              value:3
            },{
              name:'难以说话',
              value:4
            },
          ]
        },{pictureUrl:[],
          key:'consciousness',//精神意识
          label:'精神意识',
          options:[
            {
              name:'可有焦虑、烦躁',
              value:1
            },{
              name:'常焦虑、烦躁',
              value:2
            },{
              name:'常焦虑、烦躁',
              value:3
            },{
              name:'嗜睡、意识模糊',
              value:4
            },
          ]
        },{
          key:'breathing',//辅助呼吸机活动及三凹征
          label:'辅助呼吸机活动及三凹征',
          options:[
            {
              name:'常无',
              value:1
            },{
              name:'可有',
              value:2
            },{
              name:'通常有',
              value:3
            },{
              name:'胸腹反常运动',
              value:4
            },
          ]
        },{
          key:'sound',//哮鸣音
          label:'哮鸣音',
          options:[
            {
              name:'散在呼气末',
              value:1
            },{
              name:'响亮、弥漫',
              value:2
            },{
              name:'响亮、弥漫、双相',
              value:3
            },{
              name:'减弱乃至消失',
              value:4
            },
          ]
        },{
          key:'pulse',
          label:'脉率',
          options:[
            {
              name:'略增加',
              value:1
            },{
              name:'增加',
              value:2
            },{
              name:'明显增加',
              value:3
            },{
              name:'减慢或不规则',
              value:4
            },
          ]
        },{
          key:'pef',
          label:'PEF占正常预计值或本人最佳值的百分数（%）',
          options:[
            {
              name:'沙丁胺醇气雾剂（万托林）治疗后：＞80',
              value:1
            },{
              name:'沙丁胺醇气雾剂（万托林）治疗前：＞50-80          沙丁胺醇气雾剂（万托林）治疗后：＞60-80',
              value:2
            },{
              name:'沙丁胺醇气雾剂（万托林）治疗前：≤50     沙丁胺醇气雾剂（万托林）治疗后：≤60',
              value:3
            },{
              name:'无法完成检查',
              value:4
            },
          ]
        },{
          key:'oxygen',
          label:'血氧饱和度（吸空气）',
          options:[
            {
              name:'0.90-0.94',
              value:1
            },{
              name:'0.90-0.94',
              value:2
            },{
              name:'0.9',
              value:3
            },{
              name:'＜0.90',
              value:4
            },
          ]
        },
      ],
      ageForm2:{
        spirit:'',
        blood:'',
        speech:'',
        pulse:'',
        cyanosis:'',
        sound:'',
      },
      ageRules2:{
        spirit: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        blood: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        speech: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        pulse: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        cyanosis: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        sound: [
          { required: true, message: '请选择', trigger: 'change' }
        ],

      },
      featureList2:[
        {
          label:'精神意识改变',
          key:'spirit',
          options:[
            {
              name:'无',
              value:1
            },{
              name:'焦虑、烦躁、嗜睡或意识不清',
              value:2
            },
          ]
        },{
          label:'血氧饱和度（治疗前）',
          key:'blood',
          options:[
            {
              name:'≥0.92',
              value:1
            },{
              name:'＜0.92',
              value:2
            },
          ]
        },{
          label:'讲话方式',
          key:'speech',
          options:[
            {
              name:'能成句',
              value:1
            },{
              name:'能说单字',
              value:2
            },
          ]
        },{
          label:'脉率（次/min）',
          key:'pulse',
          options:[
            {
              name:'＜100',
              value:1
            },{
              name:'＞200（0—3岁）   ＞180（4—5岁）',
              value:2
            },
          ]
        },{
          label:'紫绀',
          key:'cyanosis',
          options:[
            {
              name:'无',
              value:1
            },{
              name:'可能存在',
              value:2
            },
          ]
        },{
          label:'哮鸣音',
          key:'sound',
          options:[
            {
              name:'存在',
              value:1
            },{
              name:'减弱、甚至消失',
              value:2
            },
          ]
        },
      ],
      ageForm3:{
        symptoms:'',
        night:'',
        aerosol:'',
        constrained:'',
        stLevel1:'',
        stLevel2:'',
        stLevel3:'',
        stLevel4:'',
        stLevel5:'',
      },
      ageRules3:{
        symptoms: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        night: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        aerosol: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        constrained: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel1: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel2: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel3: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel4: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel5: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
      },
      featureList3:[
        {
          label:'日间症状＞2次/周',
          key:'symptoms',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'夜间因哮喘憋醒',
          key:'night',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'沙丁胺醇气雾剂（万托林）使用＞2次/周',
          key:'aerosol',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'因哮喘而出现活动受限',
          key:'constrained',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'是否使用第1级阶梯治疗方案（未治疗）治疗是否能达到良好控制',
          key:'stLevel1',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        },{
          label:'是否使用第2级阶梯治疗方案治疗是否能达到良好控制',
          key:'stLevel2',
          list:[
            {
              name:'否',
              value:1
            }, {
              name:'丙酸氟替卡松吸入气雾剂50ug和孟鲁司特钠',
              value:2
            },{
              name:'孟鲁司特钠',
              value:3
            },{
              name:'丙酸氟替卡松吸入气雾剂125ug',
              value:4
            },
          ]

        },{
          label:'是否使用第3级阶梯治疗方案达到良好控制',
          key:'stLevel3',
          list:[
            {
              name:'否',
              value:1
            },{
              name:'沙美特罗替卡松粉吸入剂50/100ug',
              value:2
            },{
              name:'沙美特罗替卡松气雾剂25/125ug',
              value:3
            },{
              name:'布地奈德福莫特罗粉吸入剂80ug',
              value:4
            },{
              name:'丙酸氟替卡松吸入气雾剂50ug和孟鲁司特钠',
              value:5
            },{
              name:'丙酸氟替卡松吸入气雾剂125ug和孟鲁司特钠',
              value:6
            }
          ]
        },{
          label:'是否使用第4级阶梯治疗方案达到良好控制',
          key:'stLevel4',
          list:[
            {
              name:'否',
              value:1
            },{
              name:'沙美特罗替卡松粉吸入剂50/250ug',
              value:2
            },{
              name:'布地奈德福莫特罗粉吸入剂160ug',
              value:3
            },{
              name:'丙酸氟替卡松吸入气雾剂125ug 和孟鲁司特钠',
              value:4
            },{
              name:'沙美特罗替卡松粉吸入剂50/250ug和孟鲁司特钠',
              value:5
            },{
              name:'布地奈德福莫特罗粉吸入剂160ug和孟鲁司特钠',
              value:6
            }
          ]
        },{
          label:'是否使用第5级阶梯治疗方案达到良好控制',
          key:'stLevel5',
          list:[
            {
              name:'否',
              value:1
            },{
              name:'沙美特罗替卡松粉吸入剂50/250ug和孟鲁司特钠和口服最低剂量醋酸泼尼松片',
              value:2
            },{
              name:'沙美特罗替卡松粉吸入剂50/250ug和孟鲁司特钠和奥马珠单抗治疗',
              value:3
            }
          ]
        },
      ],
      ageForm4:{
        symptoms:'',
        night:'',
        aerosol:'',
        constrained:'',
        stLevel1:'',
        stLevel2:'',
        stLevel3:'',
        stLevel4:'',
        stLevel5:'',
      },
      ageRules4:{
        symptoms: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        night: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        aerosol: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        constrained: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel1: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel2: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel3: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel4: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        stLevel5: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
      },
      featureList4:[
        {
          label:'持续至少数分钟的日间症状＞1次/周',
          key:'symptoms',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'夜间因哮喘憋醒或咳嗽',
          key:'night',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'沙丁胺醇气雾剂（万托林）使用＞1次/周',
          key:'aerosol',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'因哮喘而出现活动受限（较其他儿童跑步或玩耍减少，或步行/玩耍时容易疲劳）',
          key:'constrained',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        }, {
          label:'是否使用第1级阶梯治疗方案（未治疗）治疗是否能达到良好控制',
          key:'stLevel1',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        },{
          label:'是否使用第2级阶梯治疗方案治疗是否能达到良好控制',
          key:'stLevel2',
          list:[
           {
              name:'否',
              value:1
            }, {
              name:'丙酸氟替卡松吸入气雾剂50ug和孟鲁司特钠',
              value:2
            }, {
              name:'孟鲁司特钠或丙酸氟替卡松吸入气雾剂125ug ',
              value:3
            }
          ]
        },{
          label:'是否使用第3级阶梯治疗方案达到良好控制',
          key:'stLevel3',
          list:[
            {
              name:'否',
              value:1
            }, {
              name:'酸氟替卡松吸入气雾剂125ug ',
              value:2
            }, {
              name:'丙酸氟替卡松吸入气雾剂50ug和孟鲁司特钠',
              value:3
            }
          ]
        },{
          label:'是否使用第4级阶梯治疗方案达到良好控制',
          key:'stLevel4',
          list:[
            {
              name:'否',
              value:1
            }, {
              name:'丙酸氟替卡松吸入气雾剂125ug 和孟鲁司特钠',
              value:2
            }, {
              name:'沙美特罗替卡松气雾剂25/125ug',
              value:3
            }, {
              name:'丙酸氟替卡松吸入气雾剂125ug和孟鲁司特钠和口服最低剂量醋酸泼尼松片',
              value:4
            }
          ]
        },{
          label:'是否使用第5级阶梯治疗方案达到良好控制',
          key:'stLevel5',
          list:[
            {
              name:'是',
              value:2
            },{
              name:'否',
              value:1
            },
          ]
        },
      ],
      result1Options:[
        {
          value:1,
          name:'轻度'
        },{
          value:2,
          name:'中度'
        },{
          value:3,
          name:'重度'
        },{
          value:4,
          name:'危重度'
        }
      ],
      result1OptionsLess6:[
        {
          value:1,
          name:'轻度'
        },{
          value:2,
          name:'重度'
        }
      ],
      result3Options:[
        {
          value:1,
          name:'轻度持续哮喘'
        },{
          value:2,
          name:'中度持续哮喘'
        },{
          value:3,
          name:'重度持续哮喘'
        }
      ],
      result2Options:[
        {
          value:1,
          name:'良好控制'
        },{
          value:2,
          name:'部分控制'
        },{
          value:3,
          name:'未控制'
        }
      ],
      result1:'',
      controlLevel:'',
      degree:'',
      meOption:{
        label:'name',
        value:'name',
        children:'chl',
        checkStrictly:true
      },
      medicineDisplayList:[]
    }
  },
  props: {
    title: String,
    patientId: String
  },
  components:{
    questionNaire,uploadArea,envModal,quatityModal,methodsModal,methodsModal2,quatityModal2,methodsModal3,quatityModal3
  },
  computed:{
    questionObj(){
      if(this.age <= 4){
        return {
          id:1,
          name:'儿童呼吸和哮喘控制测试'
        }
      }else if( this.age >4 && this.age <=5){
        return {
          id:2,
          name:'哮喘控制测试和儿童呼吸和哮喘控制测试'
        }
      }else if(this.age >5 && this.age < 12){
        return {
          id:3,
          name:'儿童哮喘控制测试'
        }
      }else {
        return {
          id:4,
          name:'哮喘控制测试'
        }
      }
    }
  },
  methods: {
    methodsClick(type){
      switch(type){
        case 1:
        this.$refs.methods.showModal();
        break
        case 2:
        this.$refs.methods2.showModal();
        break
        case 3:
        this.$refs.methods3.showModal();
        break

      }

    },
    quatityClick(type){
      switch(type){
        case 1:
        this.$refs.quatity.showModal();
        breakl
        case 2:
        this.$refs.quatity2.showModal();
        break
        case 3:
        this.$refs.quatity3.showModal();
        break
      }
     

    },
    envModal(){
      this.$refs.env.showModal()
    },
    resultFilter(val){
      console.log(val)
      if(this.nowchange === 1 || this.nowchange === 4){
        return "建议排除其他疾病"
        
      }
      if(this.nowchange === 2 || this.nowchange === 3){
        return val.split("?")[0]
      }
      return val 
    },
    handleMedicineChange(val){
      this.medicineDisplayList = []
      console.log(val);
      val.forEach(o=>{
        const node = deepFind(this.medicineOptions,(n)=>{
          return n.name === o
        },'chl')
        console.log(node);
        if(node){
          this.medicineDisplayList.push(node)
        }
      })
    },
    kssChange(id,val,index){
      console.log(func.arraySum(val));
      let currenIndex = this.inquiryList.findIndex(item => {return item.id === id})
      if (currenIndex > -1) {
        this.inquiryList[currenIndex].list[index]['check'] = func.arraySum(val)===0
      }
    },
    elseChange(id,val,index){
      console.log(func.arraySum(val));
      let currenIndex = this.inquiryList.findIndex(item => {return item.id === id})
      if (currenIndex > -1) {
        this.inquiryList[currenIndex].list[index]['check'] = func.arraySum(val)>0
      }
    },
    questionSubmit(val){
      console.log(val);
      this.questionResult = val.result
      this.questionScore = val.sum
      this.goodControl = val.goodControl
    },
    questionClick(){
      this.$refs.question.showModal(this.questionObj)
    },
    manxingFenjiClick(){
      this.formValid(this.age >= 6?'ageForm3':'ageForm4').then(()=>{
        const data = JSON.parse(JSON.stringify(this.age >= 6?this.ageForm3:this.ageForm4))
        console.log(data);
        for(let key in data){
          data[key] = data[key]>2?2:data[key]
        }
        manxingApi(data).then(res=>{
          this.controlLevel = res.data.data.controlLevel
          this.degree = res.data.data.degree

        })
      })

    },
    fenjiClick(){
      if(this.age > 6 ){
        this.formValid('ageForm1').then(()=>{
          over6Api(this.ageForm1).then(res=>{
            console.log(res);
            this.result1 = res.data.data
          })
        })
      }else {
        this.formValid('ageForm2').then(()=>{
          above6Api(this.ageForm2).then(res=>{
            console.log(res);
            this.result1 = res.data.data

          })
        })
      }
    },
    fenqiClick(){
      this.formValid('wjFrom').then(()=>{
        fenjiApi(this.wjFrom).then(res=>{
          console.log(res);
          this.fenqi = res.data.data
          // if([1,2].includes(res.data.data)){
          //   this.getAge()
          // }
        })
      })

    },
    getAge(){
      getAgeApi(this.patientId).then(res=>{
        console.log(res);
        this.age = res.data.data
      })
    },
    medicateChange(val,key){
      console.log(val);
      for(let i = 0;i<this.medicineDisplayList.length;i++){
        if(this.medicineDisplayList[i].type === key){
          this.medicineDisplayList.splice(i,1)
          i--
        }
      }
      val.forEach(o=>{
        const node = this[key].find(j=>{
          return j.name === o
        })
        if(node){
          node.type = key;
          this.medicineDisplayList.push(node)
        }
      })


    },
    findName(list,val,name='name'){
      const node = list.find(o=>{
        return o.value === val
      })
      if(node){
        return node[name]
      }
    },
    getMedication(){
      const data = {
        stringList:this.mainFrom.result,
        patientId:this.patientId
      }
      getMedication(data).then(res=>{
        if(res.data.data && res.data.data.length){
          this.mainFrom.medicate =res.data.data.map(o=>{
            return o.medication
          }).toString()
          this.mainFrom.charge = res.data.data.map(o=>{
            return o.advice
          }).toString()
        }

      })
    },
    // 诊断
    handleDiagnosis() {
      if (this.inquiryList && this.inquiryList.length > 0) {
          let originList = []
          this.inquiryList.forEach(item => {
            item.list.forEach(k => {
              originList.push(k)
            })
          })
          let list = originList.filter(m => m.check)
          let result = []
          if (list.length > 0) {
            originList.forEach(h => {
              let obj = {
                id: h.id,
                value: h.check ? h.check : false
              }
              result.push(obj)
            })
            diagnosis({
              inquiryTableDTOS: result
            })
            .then(res => {
              // let results = []
              if (res.data.data && res.data.data.length > 0) {
                this.mainFrom.result = res.data.data[0].ruleName
                // this.showText = res.data.data.some(o=>{
                //   return o.ruleId == 1771409851120492546
                // })
                // if(!this.showText){
                //   results = res.data.data.map(o=>{
                //     return o.asthmaType
                //   })
                // }else {
                //   results = ['doubt_asthma']
                // }
                // res.data.data.forEach(k => {
                //   if(k.value){
                //     results.push(k.asthmaType)
                //   }
                // })

              }
              // if(results.length){
              //   this.mainFrom.result  = results
              // }else {
              //   this.mainFrom.result = []
              // }
              // this.mainFrom.result
              // this.$message.success(text)
            })
          }else {
            this.$message.warning('请选择症状!')
          }
      } else {
        this.$message.warning('请选择问诊单!')
      }
    },
    // 获取问诊单下拉框
    inquiryTableListFun () {
      inquiryTableList()
       .then(response => {
        this.inquiryOptions = response.data.data
       })
    },
    // 获取诊断id
    getDiagnosticIdFun () {
      getDiagnosticId()
       .then(res => {
         this.id = res.data.data
       })
    },
    // 报告单类型
    algorithmTypeFun () {
      algorithmType()
       .then(res => {
         this.caseReportOptions= res.data.data
       })
    },
    // 打开面板
    handleOpen () {
      this.inquiryTableListFun()
      this.getDiagnosticIdFun()
      this.algorithmTypeFun()

      this.getRuleType()
      // this.getRecord()
      this.getAge()
      this.getMedicine()
    },
    getMedicine(){
      this.medicineDisplayList = []
      medicineList2().then(res=>{
        this.medicineOptions = res.data.data;
      })
      medicineList3().then(res=>{
        this.medicineOptions3 = res.data.data;
      })
      medicineList4().then(res=>{
        this.medicineOptions4 = res.data.data;
      })
      medicineList5().then(res=>{
        this.medicineOptions5 = res.data.data;
      })
    },
    getRuleType(){
      getRuleType().then(res=>{
        this.ruleTypeList = res.data.data;
      })
    },
    getRecord(){
      this.inquiryList = []
      this.inquiryList2 = []

      getRecordApi(this.patientId,this.mainFrom.description).then(res=>{
        let list;
        if(res.data.data.diagnostic!==''){
          this.inquiryList2 = [res.data.data.diagnostic]
          // list = JSON.parse(JSON.stringify(res.data.data.diagnosticInfo.classificationVOList))
          this.mainFrom.result = res.data.data.diagnosticInfo.diagnosticResult
        }else {
          list = JSON.parse(JSON.stringify(res.data.data.inquiryTableVO.classificationVOList))
          let result = []
          if (list && list.length > 0) {
            for (var i = 0; i < list.length; i++) {
              for (var j = 0; j < list[i].symptomListDTOS.length; j++) {
                list[i].symptomListDTOS[j].check = false
                this.kss = [0]
                this.gm = [0]
                this.gm2 = [0]
                this.treat = [0]
                result.push(list[i].symptomListDTOS[j])
              }
            }
          }
          let obj = {
            list: result
          }
          this.inquiryList.push(obj)
        }

        // console.log(this.inquiryList);
      })
    },
    // 面板关闭
    handleClose () {
      this.$emit('getDiagnosticListFun')
      this.srcList = []
      this.id = ''
      this.questionScore = ''
      this.result1=''
      this.controlLevel=''
      this.degree=''
      this.fenqi=''
      this.age=''
      this.mainFrom = {
        result:[],
        description: '',
        descriptionFile: '',
        // classification: [],
        medicate: '',
        charge: ''
      }
      this.inquiryOptions = []
      this.inquiryList = []
      this.diagnosisTable = []
      this.caseReportOptions = []
      this.currenRowIndex = -1
      this.reportList = []
      this.twoFrom = {
        caseReportCode: ''
      }
      this.dialogFormVisible = false

    },
    handleNowChange(val){
      if(val === 1 || val === 4){
        this.inquiryList2
      }
    },
    // 上传
    uploadUrl(file) {
      const fileName = file.file.name
      const fd = new FormData()
      fd.append('file', file.file)
      uploadFile(fd)
        .then(response => {
          this.$set(this.mainFrom, 'descriptionFile', response.data.data.link)
          this.srcList = [response.data.data.link]
        })
    },
    //化验单上传
    uploadUrl3(file,id,index){
      const fileName = file.file.name
      const fd = new FormData()
      fd.append('file', file.file)
      this.loading= true
      uploadFile3(fd)
        .then(response => {
          console.log(response);
          // let currenIndex = this.inquiryList.findIndex(item => {return item.id === id})
          // if (currenIndex > -1) {
          //   this.inquiryList[currenIndex].list[index]['check'] = response.data.data.isItSelected
          // }
          // this.loading= false
          // this.uploadText = response.data.data.recognizedValues
        }).catch(err=>{
        this.loading= false
      })

    },
    // 上传
    uploadUrl2(file,id,index) {
      const fileName = file.file.name
      const fd = new FormData()
      fd.append('file', file.file)
      fd.append('type', 1)
      fd.append('patientId', this.patientId)
      this.loading= true
      uploadFile2(fd)
        .then(response => {
          let currenIndex = this.inquiryList.findIndex(item => {return item.id === id})
          if (currenIndex > -1) {
            this.inquiryList[currenIndex].list[index]['check'] = response.data.data.isItSelected
          }
          this.loading= false
          this.uploadText = response.data.data.recognizedValues
        }).catch(err=>{
        this.loading= false
      })
    },
    //辅助诊断
    inq2Click(){
      getRecordApi2(this.patientId).then(res=>{
        console.log(res);
        let list = JSON.parse(JSON.stringify(res.data.data.inquiryTableVO.classificationVOList))
        let result = []
        if (list && list.length > 0) {
          for (var i = 0; i < list.length; i++) {
            for (var j = 0; j < list[i].symptomListDTOS.length; j++) {
              list[i].symptomListDTOS[j].check = false
              this.kss = [0]
              this.gm = [0]
              this.gm2 = [0]
              this.treat = [0]
              result.push(list[i].symptomListDTOS[j])
            }
          }
        }
        let obj = {
          list: result
        }
        this.inquiryList3.push(obj)
      })

    },
    // 选择问诊单
    handleClassification() {
      this.inquiryList = []
      if (this.mainFrom.classification && this.mainFrom.classification.length > 0) {
        this.mainFrom.classification.forEach(item => {
          this.getDetailFun(item)
        })
      }
    },
    // 获取问诊单的问诊项
    getDetailFun (id) {
      getDetail().then((res) => {
        const list = JSON.parse(JSON.stringify(res.data.data.classificationVOList))
        const originList = JSON.parse(JSON.stringify(this.inquiryList))
        let result = []
        if (list && list.length > 0) {
          for (var i = 0; i < list.length; i++) {
            for (var j = 0; j < list[i].symptomListDTOS.length; j++) {
              result.push(list[i].symptomListDTOS[j])
            }
          }
        }
        let obj = {
          id: id,
          list: result
        }
        if (originList.findIndex(k => k.id === id) === -1) {
          this.inquiryList.push(obj)
        }
        console.log(this.inquiryList);
      })
    },
    // 是否有症状
    handleChange(id, status, index) {
      let currenIndex = this.inquiryList.findIndex(item => {return item.id === id})
      if (currenIndex > -1) {
        this.inquiryList[currenIndex].list[index]['check'] = status
      }
    },
    // 获取问诊单名称
    getInqueryName(id) {
      let name = ''
      let index = this.inquiryOptions.findIndex(k => {return k.id === id})
      if (index > -1) {
        name = this.inquiryOptions[index].inquiryName
      }
      return name
    },
    // 新增诊断结果
    resultAdd () {
      this.$prompt('请输入诊断结果', '诊断结果', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          this.diagnosisTable.push({
            content: value
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消输入'
          })
        })
    },
    // 删除诊断结果
    handleDelete (index) {
      this.diagnosisTable.splice(index, 1)
    },
    // 提交基础信息
    mainFromSubmit() {
      console.log(this.medicineDisplayList);
      if(this.fenqi === 1 && this.result1===''){
        this.$message.warning('请填写问卷')
        return
      }
      if(this.fenqi === 2 && this.controlLevel===''){
        this.$message.warning('请填写问卷')
        return
      }
      let charge = ''
      if(this.inquiryList2.length){
        charge+=`哮喘分级为：${this.findName(this.fqList,this.fenqi)}`;
        if(this.fenqi === 1){
          charge+=`,哮喘急性发作严重度分级：${this.findName((this.age>=6?this.result1Options:this.result1OptionsLess6),this.result1)}`
        }
        if(this.fenqi === 2){
          charge+=`,哮喘控制水平的分级为：${this.findName(this.result2Options,this.controlLevel)}，病情严重程度分级为：${this.findName(this.result3Options,this.degree)}`
        }
      }
      if(this.questionResult){
        charge+=this.questionResult
      }
      let medicate = '';
      this.medicineDisplayList.forEach(me=>{
        let dosage = []
        me.specifications.forEach((spe,i)=>{
          dosage.push(me[`spe${i}`]+spe)
        })
        let textarr = [me.name,me.dosageValue,...dosage,me.datevalue+me.course+'为一个疗程']
        medicate+=textarr.toString()
      })
      Promise.all( [this.formValid('mainFrom')]).then(res=>{
        let params = {
          description: this.mainFrom.description,
          descriptionFile: this.mainFrom.descriptionFile,
          id: this.id,
          patientId: this.patientId,
          diagnosticResult: this.inquiryList2.length?this.resultFilter(this.mainFrom.result[0]):this.mainFrom.result,
          evaluation: this.inquiryList,
          medicate,
          charge,
          pictureUrl:this.pictureUrl,
        }
        console.log(params);
        peportInfoOne(params)
          .then(() => {
            this.$message.success('保存成功')

          })
      })
    },
    formValid(name){
      return new Promise((resolve,reject)=>{
        this.$refs[name].validate((valid) => {
          if (valid) {
            resolve()
          }else {
            reject()
          }
        })
      })
    },
    // 上传报告单
    uploadReport(file) {
      const fileName = file.file.name
      const fd = new FormData()
      fd.append('file', file.file)
      fd.append('caseReportCode', this.twoFrom.caseReportCode)
      fd.append('diagnosticId', this.id)
      fd.append('patientId', this.patientId)
      const loading = this.$loading({
        lock: true,
        text: '识别中，请等待!',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      filetwo(fd)
        .then(response => {
          const list = JSON.parse(JSON.stringify(response.data.data.reportData))
          this.reportList.push({
            uuid: response.data.data.id,
            reportImgUrl: response.data.data.reportImgUrl,
            checkDate: response.data.data.checkDate,
            reportName: response.data.data.reportName,
            reportData: list
          })
          loading.close()
        })
        .catch(() => {
          loading.close()
        })
    },
    // 编辑报告单
    handleEdit(uuid, colData, index, cellData, currentIndex) {
      let _this = this
      if (_this.currenRowIndex === -1) {
        if (currentIndex > 0) {
          _this.currenRowIndex = currentIndex
          let tabIndex = _this.reportList.findIndex(k => {return k.uuid === uuid})
          if (tabIndex > -1) {
            if (cellData.key === 'edit') {
              _this.$nextTick(() => {
                _this.reportList[tabIndex].reportData[index][currentIndex].value = '保存'
                _this.reportList[tabIndex].reportData[index][currentIndex].key = 'save'
              })
            }
          }
        }
      } else {
        this.$message.warning('请先保存修改的数据')
      }
    },
    // 保存报告单
    handleSave(uuid, colData, index, cellData, currentIndex) {
      let list = []
      let tabIndex = this.reportList.findIndex(k => {return k.uuid === uuid})
      if (tabIndex > -1) {
        const origin = JSON.parse(JSON.stringify(this.reportList[tabIndex].reportData))
        for (var i = 0; i < origin.length; i++) {
          if (i < origin.length -1) {
            for (var j = 0; j < origin[i].length; j++) {
              if (j === currentIndex) {
                let obj = {
                  code: origin[i][0].key, // 表头code
                  id: origin[i][currentIndex].key, // 表行中的id
                  value: origin[i][currentIndex].value //需要修改的值
                }
                list.push(obj)
              }
            }
          }
        }
        editReportData(list)
        .then(() => {
          this.$message.success('成功')
          let _this = this
          _this.$nextTick(() => {
            _this.reportList[tabIndex].reportData[index][currentIndex].value = '编辑'
            _this.reportList[tabIndex].reportData[index][currentIndex].key = 'edit'
            _this.currenRowIndex = -1
          })
        })
      }
    },
    // 切换tab
    handleTabClick(tab, event) {
      this.currenRowIndex = -1
    },
    // 提交
    twoFromSubmit () {
      if(this.twoFrom.caseReportCode === 'OTHER'){
        const data = {
          diagnosticId:this.id,
          pictureUrl:this.reportPictures
        }
        saveOtherReport(data).then(res=>{
          this.handleClose()
        })
      }else{
        if(this.inquiryList2.length){
        this.$refs.twoFrom.validate((valid) => {
          if (valid) {
            const data = {
              id: this.id,
              ...this.twoFrom
            }
            delete data.caseReportCode
            saveMedicine(data).then(res=>{
              this.$refs.mainFrom.validate(isvalid=>{
                if(isvalid){
                  this.handleClose()
                }else {
                  this.$message.warning('请维护基本信息')
                }
              })

            })

          }
        })
      }else {
        this.$refs.mainFrom.validate(valid=>{
          if(valid){
            this.handleClose()
          }else {
            this.$message.warning('请维护基本信息')
          }
        })
      }
      }


    }
  },
  filters:{


  }
}
</script>
<style scoped>
.container {
  width: 100%;
}
.ml-10{
  margin-left: 10px;
}
.ml-20{
  margin-left: 20px;
}
.m-t-20{
  margin-top: 20px;
}
.w-240 {
  width: 240px;
}
.flex-center{
  display: flex;
  align-items: center;
}
.flex-column{
  display: flex;
  flex-direction: column;
}
.sub-bottom {
  margin: 20px 0;
  text-align: right;
}
.tab-wrap {
  width: 100%;
  height: 450px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 10px;
  box-sizing: border-box;
}
.oper {
 display: inline-block;
 width: 50px;
 height: 20px;
 color: #409EFF;
 margin-right: 10px;
 cursor: pointer;
}
.title {
  width: 100%;
  height: 5px;
  line-height: 5px;
  overflow: hidden;
  font-size: 14px;
  color: #409EFF;
  font-weight:  bold;
  padding: 10px 0;
  border-left: 5px solid #409EFF;
  text-indent: 10px;
}
.report-wrap {
  width: 100%;
  overflow: auto;
}
.report-content {
  width: 100%;
  font-size: 12px;
  display: flex;
}
.col {
  display: inline-block;
  width: 90px;
}
.cell {
  width: 90px;
  height: 32px;
  overflow: hidden;
  text-align: left;
}
.blue {
  color: #409EFF;
  cursor: pointer;
}
</style>
